#ifndef PROC_GBA_PATCH_H_
#define PROC_GBA_PATCH_H_

#include "nds.h"

typedef enum {
	UNKNOW =0,
	SRAM_TYPE=1,
	EEPROM_TYPE=2,
	FLASH_TYPE=3,
	FLASH512_TYPE=4,
	FLASH1M_TYPE=5,
}SAVERTYPE ;

#define e11x_newwrite_LEN 24
#define e11x_code_LEN 188
#define e11x_newread_LEN 10
#define e11x_read_LEN 10
#define e11x_write_LEN 24
#define e12x_read_LEN 16
#define e12x_write_LEN 16
#define e12x_identify_LEN 16
#define e12x_newidentify_LEN 2
#define e12x_newread_LEN 40
#define e12x_newwrite_LEN 40
#define f12x_read_LEN 16
#define f12x_write_LEN 16
#define f12x_identify_LEN 16
#define f12x_erase_LEN 16
#define f12x_erasesec_LEN 16
#define f12x_newidentify_LEN 8
#define f12x_return0_LEN 8
#define f12x_newread_LEN 38
#define f12x_newwrite_LEN 42
#define f121_write_LEN 32
#define f121_identify_LEN 32
#define f121_erase_LEN 32
#define f121_erasesec_LEN 32
#define f121_newidentify_LEN 14
#define f121_return0_LEN 8
#define f121_newwrite_LEN 40
#define f512_130_identify_LEN 16
#define f512_130_read_LEN 16
#define f512_130_write_LEN 16
#define f512_130_erase_LEN 16
#define f512_130_erasesec_LEN 16
#define f512_130_newidentify_LEN 8
#define f512_130_return0_LEN 8
#define f512_130_newread_LEN 38
#define f512_130_newwrite_LEN 42
#define f1M_102_orig1_LEN 12
#define f1M_102_orig2_LEN 16
#define f1M_102_orig3_LEN 32
#define f1M_102_orig4_LEN 24
#define f1M_102_orig5_LEN 24
#define f1M_102_orig6_LEN 24
#define flash1M103_identify_LEN 16
#define f1M_102_repl1_LEN 12
#define f1M_102_repl2_LEN 16
#define f1M_102_repl3_LEN 32
#define f1M_102_repl4_LEN 76
#define f1M_102_repl5_LEN 88
#define f1M_102_repl6_LEN 104
#define flash1M103_new_identify_LEN 8
#define flash1M103_Setrampage_LEN 12
#define flash1M103_Erase_LEN 24
#define flash1M103_Program_LEN 32
#define flash1M103_Write_LEN 24
#define flash1M103_new_Setrampage_LEN 12
#define	flash1M103_new_Erase_LEN 76
#define flash1M103_new_Program_LEN 44
#define flash1M103_new_Write_LEN 104

static unsigned char e11x_newwrite[]=
{
	0xe0,0x20,0x00,0x05,0x01,0x88,0x01,0x22,
	0x08,0x1c,0x10,0x40,0x02,0x1c,0x11,0x04,
	0x08,0x0c,0x00,0x28,0x01,0xd0,0x1b,0xe0,
};
static unsigned char e11x_code[]=
{
	0x39,0x68,0x27,0x48,0x81,0x42,0x23,0xd0,
	0x89,0x1c,0x08,0x88,0x01,0x28,0x02,0xd1,
	0x24,0x48,0x78,0x60,0x33,0xe0,0x00,0x23,
	0x00,0x22,0x89,0x1c,0x10,0xb4,0x01,0x24,
	0x08,0x68,0x20,0x40,0x5b,0x00,0x03,0x43,
	0x89,0x1c,0x52,0x1c,0x06,0x2a,0xf7,0xd1,
	0x10,0xbc,0x39,0x60,0xdb,0x01,0x02,0x20,
	0x00,0x02,0x1b,0x18,0x0e,0x20,0x00,0x06,
	0x1b,0x18,0x7b,0x60,0x39,0x1c,0x08,0x31,
	0x08,0x88,0x09,0x38,0x08,0x80,0x16,0xe0,
	0x15,0x49,0x00,0x23,0x00,0x22,0x10,0xb4,
	0x01,0x24,0x08,0x68,0x20,0x40,0x5b,0x00,
	0x03,0x43,0x89,0x1c,0x52,0x1c,0x06,0x2a,
	0xf7,0xd1,0x10,0xbc,0xdb,0x01,0x02,0x20,
	0x00,0x02,0x1b,0x18,0x0e,0x20,0x00,0x06,
	0x1b,0x18,0x08,0x3b,0x3b,0x60,0x0b,0x48,
	0x39,0x68,0x01,0x60,0x0a,0x48,0x79,0x68,
	0x01,0x60,0x0a,0x48,0x39,0x1c,0x08,0x31,
	0x0a,0x88,0x80,0x21,0x09,0x06,0x0a,0x43,
	0x02,0x60,0x07,0x48,0x00,0x47,0x00,0x00,
	0x00,0x00,0x00,0x0d,0x00,0x00,0x00,0x0e,
	0x04,0x00,0x00,0x0e,0xd4,0x00,0x00,0x04,
	0xd8,0x00,0x00,0x04,0xdc,0x00,0x00,0x04,
	0xff,0xff,0xff,0x08,0x22,0x4c,0x84,0x42,
	0x20,0xd0,0x80,0x1c,0x04,0x88,0x01,0x25,
	0x2c,0x40,0x01,0x2c,0x02,0xd1,0x80,0x1e,
	0x1e,0x49,0x2e,0xe0,0x00,0x23,0x00,0x24,
	0x80,0x1c,0x40,0xb4,0x01,0x26,0x05,0x68,
	0x35,0x40,0x5b,0x00,0x2b,0x43,0x80,0x1c,
	0x64,0x1c,0x06,0x2c,0xf7,0xd1,0x40,0xbc,
	0xdb,0x01,0x02,0x24,0x24,0x02,0x1b,0x19,
	0x0e,0x24,0x24,0x06,0x1b,0x19,0x19,0x1c,
	0x09,0x3a,0x16,0xe0,0x12,0x48,0x00,0x23,
	0x00,0x24,0x40,0xb4,0x01,0x26,0x05,0x68,
	0x35,0x40,0x5b,0x00,0x2b,0x43,0x80,0x1c,
	0x64,0x1c,0x06,0x2c,0xf7,0xd1,0x40,0xbc,
	0xdb,0x01,0x02,0x24,0x24,0x02,0x1b,0x19,
	0x0e,0x24,0x24,0x06,0x1b,0x19,0x08,0x3b,
	0x18,0x1c,0x08,0x4c,0x20,0x60,0x08,0x4c,
	0x21,0x60,0x08,0x49,0x80,0x20,0x00,0x06,
	0x02,0x43,0x0a,0x60,0x06,0x4c,0x20,0x47,
	0x00,0x00,0x00,0x0d,0x00,0x00,0x00,0x0e,
	0x04,0x00,0x00,0x0e,0xd4,0x00,0x00,0x04,
	0xd8,0x00,0x00,0x04,0xdc,0x00,0x00,0x04,
	0xff,0xff,0xff,0x08
};

static unsigned char e11x_newread[]=
{
	0x00,0x48,0x00,0x47,0x01,0xff,0xff,0x08,
	0x79,0x68,0x01,0x4c,0x20,0x47,0x00,0x00,
	0x01,0xff,0xff,0x08
};
static unsigned char e11x_read[]=
{
	0x0e,0x48,0x39,0x68,0x01,0x60,0x0e,0x48,
	0x79,0x68
};

static unsigned char e11x_write[]=
{
	0xd0,0x20,0x00,0x05,0x01,0x88,0x01,0x22,
	0x08,0x1c,0x10,0x40,0x02,0x1c,0x11,0x04,
	0x08,0x0c,0x00,0x28,0x01,0xd0,0x1b,0xe0,
};
static u8 e12x_read[]=
{
	0x70,0xb5,0xa2,0xb0,0x0d,0x1c,0x00,0x04,
	0x03,0x0c,0x03,0x48,0x00,0x68,0x80,0x88
};
static u8 e124_write[]=
{
	0xF0,0xb5,0xaC,0xb0,0x0d,0x1c,0x00,0x04,
	0x01,0x0c,0x12,0x06,0x17,0x0E,0x03,0x48
};
static u8 e12x_identify[]=
{
	0x00,0x04,0x00,0x0c,0x00,0x22,0x04,0x28,
	0x08,0xd1,0x02,0x49,0x02,0x48,0x08,0x60
};
static unsigned char e124_write2[]=
{
	0xF0 , 0xB5 , 0x47 , 0x46 , 0x80 , 0xB4 , 0xAC , 0xB0 , 
	0x0E , 0x1C , 0x00 , 0x04 , 0x05 , 0x0C , 0x12 , 0x06 , 
	0x12 , 0x0E , 0x90 , 0x46 , 0x03 , 0x48 , 0x00 , 0x68 , 
	0x80 , 0x88 , 0x85 , 0x42 , 0x06 , 0xD3 , 0x02 , 0x48
};
static unsigned char e12x_newidentify[]=
{
	0x00,0x22
};
static unsigned char e12x_newread[]=
{
	0x70,0xb5,0x00,0x04,0x0a,0x1c,0x40,0x0b,
	0xe0,0x21,0x09,0x05,0x41,0x18,0x07,0x31,
	0x00,0x23,0x08,0x78,0x10,0x70,0x01,0x33,
	0x01,0x32,0x01,0x39,0x07,0x2b,0xf8,0xd9,
	0x00,0x20,0x70,0xbc,0x02,0xbc,0x08,0x47
};

static unsigned char e12x_newwrite[]=
{
	0x70,0xb5,0x00,0x04,0x0a,0x1c,0x40,0x0b,
	0xe0,0x21,0x09,0x05,0x41,0x18,0x07,0x31,
	0x00,0x23,0x10,0x78,0x08,0x70,0x01,0x33,
	0x01,0x32,0x01,0x39,0x07,0x2b,0xf8,0xd9,
	0x00,0x20,0x70,0xbc,0x02,0xbc,0x08,0x47
};

static unsigned char e12x_write[]=
{
	0x30,0xb5,0xa9,0xb0,0x0d,0x1c,0x00,0x04,
	0x04,0x0c,0x03,0x48,0x00,0x68,0x80,0x88
};

static unsigned char f12x_read[]=
{
	0xf0,0xb5,0xa0,0xb0,0x0d,0x1c,0x16,0x1c,
	0x1f,0x1c,0x00,0x04,0x04,0x0c,0x08,0x4a,
	0x10,0x88,0x08,0x49,0x08,0x40,0x03,0x21,
	0x08,0x43,0x10,0x80,0x06,0x4b,0x01,0x20
};
static unsigned char f12x_write[]=
{
	0xf0,0xb5,0x90,0xb0,0x0f,0x1c,0x00,0x04,
	0x04,0x0c,0x0f,0x2c,0x04,0xd9,0x01,0x48,
	0x40,0xe0,0x00,0x00,0xff,0x80,0x00,0x00,
	0x20,0x1c,0xff,0xf7,0xd7,0xfe,0x00,0x04
};
static unsigned char f12x_identify[]=
{
	0xff,0xf7,0xaa,0xff,0x00,0x04,0x03,0x0c,
	0x03,0x4a,0x01,0x24,0x07,0xe0,0x00,0x00,
	0x04,0x02,0x00,0x04,0xfc,0xff,0x00,0x00,
	0xbc,0x34,0x00,0x08,0x04,0x32,0x11,0x68
};
static unsigned char f12x_erasesec[]=
{
	0x70,0xb5,0x46,0x46,0x40,0xb4,0x90,0xb0,
	0x00,0x04,0x03,0x0c,0x0f,0x2b,0x3b,0xd8,
	0x17,0x4e,0x31,0x88,0x17,0x48,0x80,0x46,
	0x01,0x40,0x17,0x48,0x02,0x68,0x10,0x8a
};
static unsigned char f12x_erase[]=
{
	0x70,0xb5,0x90,0xb0,0x15,0x4d,0x29,0x88,
	0x15,0x4e,0x31,0x40,0x15,0x48,0x00,0x68,
	0x00,0x8a,0x08,0x43,0x28,0x80,0x14,0x49,
	0xaa,0x24,0x0c,0x70,0x13,0x4b,0x55,0x22
};

static unsigned char f12x_MNidentify[]=
{
	0x1b,0x23,0x1b,0x02,0x32,0x20,0x03,0x43
};
static unsigned char f12x_return0[]=
{
	0x00,0xb5,0x00,0x20,0x02,0xbc,0x08,0x47
};
static unsigned char f12x_newread[]=
{
	0x70,0xb5,0xa0,0xb0,0x00,0x03,0x40,0x18,
	0xe0,0x21,0x09,0x05,0x09,0x18,0x08,0x78,
	0x10,0x70,0x01,0x3b,0x01,0x32,0x01,0x31,
	0x00,0x2b,0xf8,0xd1,0x00,0x20,0x20,0xb0,
	0x70,0xbc,0x02,0xbc,0x08,0x47
};
static unsigned char f12x_newwrite[]=
{
	0x7c,0xb5,0x90,0xb0,0x00,0x03,0x0a,0x1c,
	0xe0,0x21,0x09,0x05,0x09,0x18,0x01,0x23,
	0x1b,0x03,0x10,0x78,0x08,0x70,0x01,0x3b,
	0x01,0x32,0x01,0x31,0x00,0x2b,0xf8,0xd1,
	0x00,0x20,0x10,0xb0,0x7c,0xbc,0x02,0xbc,
	0x08,0x47
};
static unsigned char f121_write[]=
{
	0x80,0xb5,0x94,0xb0,0x6f,0x46,0x79,0x60,
	0x39,0x1c,0x08,0x80,0x38,0x1c,0x01,0x88,
	0x0f,0x29,0x03,0xd9,0x00,0x48,0x73,0xe0,
	0xff,0x80,0x00,0x00,0x38,0x1c,0x01,0x88
};
static unsigned char f121_identify[]=
{
	0x90,0xb5,0x93,0xb0,0x6f,0x46,0x39,0x1d,
	0x08,0x1c,0x00,0xf0,0xaf,0xf9,0x38,0x1d,
	0x41,0x1c,0x79,0x64,0x09,0x48,0xaa,0x21,
	0x01,0x70,0x09,0x48,0x55,0x21,0x01,0x70
};
static unsigned char f121_erase[]=
{
	0x80,0xb5,0x92,0xb0,0x6f,0x46,0x1f,0x48,
	0x1e,0x49,0x0a,0x88,0x1e,0x4b,0x11,0x1c,
	0x19,0x40,0x1e,0x4b,0x1a,0x68,0x12,0x8a,
	0x11,0x43,0x0a,0x1c,0x02,0x80,0x1c,0x48
};
static unsigned char f121_erasesec[]=
{
	0x80,0xb5,0x94,0xb0,0x6f,0x46,0x39,0x1c,
	0x08,0x80,0x38,0x1c,0x01,0x88,0x0f,0x29,
	0x04,0xd9,0x01,0x48,0x56,0xe0,0x00,0x00,
	0xff,0x80,0x00,0x00,0x23,0x48,0x23,0x49
};
static unsigned char f121_newidentify[]=
{
	0x00,0xb5,0x1B,0x20,0x00,0x02,0x32,0x21,
	0x08,0x43,0x02,0xbc,0x08,0x47
};
static unsigned char f121_return0[]=
{
	0x00,0xb5,0x00,0x20,0x02,0xbc,0x08,0x47
};
static unsigned char f121_newwrite[]=
{
	0x7c,0xb5,0x00,0x07,0x00,0x0c,0x0a,0x1c,
	0xe0,0x21,0x09,0x05,0x09,0x18,0x01,0x23,
	0x1b,0x03,0x10,0x78,0x08,0x70,0x01,0x3b,
	0x01,0x32,0x01,0x31,0x00,0x2b,0xf8,0xd1,
	0x00,0x20,0x7c,0xbc,0x02,0xbc,0x08,0x47
};
static unsigned char f512_130_identify[]=
{
	0xff,0xf7,0x88,0xfd,0x00,0x04,0x03,0x0c,
	0x03,0x4a,0x01,0x24,0x07,0xe0,0x00,0x00,
	0x04,0x02,0x00,0x04,0xfc,0xff,0x00,0x00,
	0x60,0x0e,0x36,0x08,0x04,0x32,0x11,0x68
};
static unsigned char f512_130_read[]=
{
	0xf0,0xb5,0xa0,0xb0,0x0d,0x1c,0x16,0x1c,
	0x1f,0x1c,0x03,0x04,0x1c,0x0c,0x0f,0x4a,
	0x10,0x88,0x0f,0x49,0x08,0x40,0x03,0x21,
	0x08,0x43,0x10,0x80,0x0d,0x48,0x00,0x68,
	0x01,0x68,0x80,0x20
};
static unsigned char f512_130_write[]=
{
	0xf0,0xb5,0x90,0xb0,0x0f,0x1c,0x00,0x04,
	0x04,0x0c,0x03,0x48,0x00,0x68,0x40,0x89,
	0x84,0x42,0x05,0xd3,0x01,0x48,0x41,0xe0,
	0x40,0xf3,0x00,0x02,0xff,0x80,0x00,0x00,
	0x20,0x1c,0xff,0xf7,0xd3,0xfe,0x00,0x04
};
static unsigned char f512_130_erase[]=
{
	0x70,0xb5,0x90,0xb0,0x15,0x4d,0x29,0x88,
	0x15,0x4e,0x31,0x40,0x15,0x48,0x00,0x68,
	0x00,0x8a,0x01,0x43,0x29,0x80,0x14,0x49,
	0xaa,0x24,0x0c,0x70,0x13,0x4b,0x55,0x22
};
static unsigned char f512_130_erasesec[]=
{
	0x70,0xb5,0x46,0x46,0x40,0xb4,0x90,0xb0,
	0x00,0x04,0x03,0x0c,0x0f,0x2b,0x3b,0xd8,
	0x17,0x4e,0x31,0x88,0x17,0x48,0x80,0x46,
	0x01,0x40,0x17,0x48,0x02,0x68,0x10,0x8a
};
static unsigned char f512_130_MNidentify[]=
{
	0x1b,0x23,0x1b,0x02,0x32,0x20,0x03,0x43
};
static unsigned char f512_130_return0[]=
{
	0x00,0xb5,0x00,0x20,0x02,0xbc,0x08,0x47
};
static unsigned char f512_130_newread[]=
{
	0x70,0xb5,0xa0,0xb0,0x00,0x03,0x40,0x18,
	0xe0,0x21,0x09,0x05,0x09,0x18,0x08,0x78,
	0x10,0x70,0x01,0x3b,0x01,0x32,0x01,0x31,
	0x00,0x2b,0xf8,0xd1,0x00,0x20,0x20,0xb0,
	0x70,0xbc,0x02,0xbc,0x08,0x47
};
static unsigned char f512_130_newwrite[]=
{
	0x7c,0xb5,0x90,0xb0,0x00,0x03,0x0a,0x1c,
	0xe0,0x21,0x09,0x05,0x09,0x18,0x01,0x23,
	0x1b,0x03,0x10,0x78,0x08,0x70,0x01,0x3b,
	0x01,0x32,0x01,0x31,0x00,0x2b,0xf8,0xd1,
	0x00,0x20,0x10,0xb0,0x7c,0xbc,0x02,0xbc,
	0x08,0x47
};
static unsigned char f1M_102_orig1[]=
{
	0x00,0x06,0x00,0x0E,
	0x05,0x4B,0xAA,0x21,0x19,0x70,0x05,0x4A,
};
static unsigned char f1M_102_orig2[]=
{
	0xaa,0x20,0x10,0x70,0x05,0x49,0x55,0x20,
	0x08,0x70,0x90,0x20,0x10,0x70,0x10,0xa9,
};
static unsigned char f1M_102_orig3[]=
{
	0x00,0x05,0x01,0xf0,0xd3,0xf8,0x00,0x06,
	0x00,0x0E,0x04,0x43,0x07,0x49,0xaa,0x20,
	0x08,0x70,0x07,0x4a,0x55,0x20,0x10,0x70,
	0xf0,0x20,0x08,0x70,0x08,0x70,0x10,0xa9,
};
static unsigned char f1M_102_orig3_1[]=
{
	0x00,0x05,0x05,0xf0,0x45,0xf9,0x00,0x06,
	0x00,0x0E,0x04,0x43,0x07,0x49,0xaa,0x20,
	0x08,0x70,0x07,0x4a,0x55,0x20,0x10,0x70,
	0xf0,0x20,0x08,0x70,0x08,0x70,0x10,0xa9,
};
static unsigned char f1M_102_orig4[]=
{
	0xf0,0xb5,0x90,0xb0,0x00,0x04,0x06,0x0c,
	0x03,0x48,0x00,0x68,0x40,0x89,0x86,0x42,
	0x06,0xd3,0x02,0x48,0x54,0xe0,0x00,0x00,
	0x80,0x73,0x00,0x03,0xff,0x80,0x00,0x00,
	0x30,0x09,0x00,0x06,0x00,0x0e,0xff,0xf7,
	0x91,0xfc,0x0f,0x20,0x06,0x40,0x00,0x27,
	0x19,0x4b,0x19,0x88,0x19,0x48,0x01,0x40,
	0x19,0x48,0x02,0x68,0x01,0x8a,0x01,0x43,
	0x19,0x80,0x14,0x7a,0x30,0x1c,0xa0,0x40,
	0x04,0x1c,0xe0,0x20,
};
static unsigned char f1M_102_orig5[]=
{
	0xf0,0xb5,0x90,0xb0,0x0E,0x1c,0x01,0x04,
	0x0c,0x0c,0x12,0x06,0x17,0x0e,0x18,0x4d,
	0x28,0x68,0x40,0x68,0x86,0x42,0x37,0xd2,
	0x08,0x0d,0x00,0x06,0x00,0x0e,0xFF,0xf7,
	0x2d,0xfc,0x0f,0x20,0x29,0x68,0x04,0x40,
	0x09,0x7a,0x8c,0x40,0xe0,0x21,0x09,0x05,
	0x70,0x18,0x24,0x18,0x68,0x46,0xff,0xf7,
	0x2b,0xfd,0x0e,0x4a,0x10,0x88,0x0e,0x49,
	0x08,0x40,0x29,0x68,0x09,0x8a,0x08,0x43,
	0x10,0x80,0x0C,0x4A,0xaa,0x20,0x10,0x70,
	0x0b,0x49,0x55,0x20,0x08,0x70,0xa0,0x20,
};
static unsigned char f1M_102_orig6[]=
{
	0xf0,0xb5,0x90,0xb0,0x0f,0x1c,0x00,0x04,
	0x04,0x0c,0x03,0x48,0x00,0x68,0x40,0x89,
	0x84,0x42,0x05,0xd3,0x01,0x48,0x40,0xe0,
	0x80,0x73,0x00,0x03,0xff,0x80,0x00,0x00,
	0x20,0x1c,0xff,0xf7,0x1f,0xff,0x00,0x04,
	0x05,0x0c,0x00,0x2d,0x34,0xd1,0x20,0x09,
	0x00,0x06,0x00,0x0e,0xff,0xf7,0xbc,0xfb,
	0x0f,0x20,0x04,0x40,0x68,0x46,0xff,0xf7,
	0xc1,0xfc,0x09,0x4b,0x19,0x88,0x09,0x48,
	0x01,0x40,0x09,0x48,0x02,0x68,0x10,0x8a,
	0x01,0x43,0x19,0x80,0x07,0x49,0x50,0x68,
	0x08,0x80,0x10,0x7a,0x84,0x40,0xe0,0x20,
	0x00,0x05,0x24,0x18,0x0e,0x1c,0x0c,0xe0,
};
static unsigned char flash1M103_identify[]=
{
	0xff,0xf7,0x88,0xfd,0x00,0x04,0x03,0x0c,
	0x03,0x4a,0x01,0x24,0x07,0xe0,0x00,0x00,
	0x04,0x02,0x00,0x04,0xfc,0xff,0x00,0x00,
	0x60,0x0e,0x36,0x08,0x04,0x32,0x11,0x68
};
static unsigned char f1M_102_repl4[]=
{
	0x00,0xb5,0x00,0x20,0x02,0xbc,0x08,0x47,
	0x70,0xb4,0x0a,0x49,0xd2,0x22,0x12,0x02,
	0x0a,0x80,0x09,0x49,0x15,0x23,0x1b,0x02,
	0x0b,0x80,0x08,0x49,0x0a,0x80,0x08,0x49,
	0x0b,0x80,0x08,0x49,0x00,0x01,0x00,0x30,
	0x08,0x80,0x07,0x49,0x0b,0x80,0x70,0xbc,
	0x70,0x47,0x00,0x00,0x00,0x00,0xfe,0x09,
	0x00,0x00,0x00,0x08,0x00,0x00,0x02,0x08,
	0x00,0x00,0x04,0x08,0x00,0x00,0xc0,0x09,
	0x00,0x00,0xfc,0x09,
};
static unsigned char f1M_102_repl5[]=
{
	0x78,0xb5,0x00,0x06,0x03,0x0f,0x00,0x01,
	0x00,0x04,0x40,0x18,0xe0,0x21,0x09,0x05,
	0x09,0x18,0x0b,0x48,0xd2,0x25,0x2d,0x02,
	0x05,0x80,0x0a,0x48,0x15,0x26,0x36,0x02,
	0x06,0x80,0x09,0x48,0x05,0x80,0x09,0x48,
	0x06,0x80,0x09,0x48,0x1b,0x01,0x00,0x33,
	0x03,0x80,0x08,0x48,0x06,0x80,0x0a,0x70,
	0x00,0x20,0x78,0xbc,0x02,0xbc,0x08,0x47,
	0x00,0x00,0xfe,0x09,0x00,0x00,0x00,0x08,
	0x00,0x00,0x02,0x08,0x00,0x00,0x04,0x08,
	0x00,0x00,0xc0,0x09,0x00,0x00,0xfc,0x09,
};

static unsigned char f1M_102_repl6[]=
{
	0x7c,0xb5,0x00,0x06,0x04,0x0f,0x00,0x01,
	0x00,0x0c,0x0a,0x1c,0xe0,0x21,0x09,0x05,
	0x09,0x18,0x01,0x23,0x1b,0x03,0x0e,0x48,
	0xd2,0x25,0x2d,0x02,0x05,0x80,0x0d,0x48,
	0x15,0x26,0x36,0x02,0x06,0x80,0x0c,0x48,
	0x05,0x80,0x0c,0x48,0x06,0x80,0x0c,0x48,
	0x24,0x01,0x00,0x34,0x04,0x80,0x0b,0x48,
	0x06,0x80,0x10,0x78,0x08,0x70,0x01,0x3b,
	0x01,0x32,0x01,0x31,0x00,0x2b,0xf8,0xd1,
	0x00,0x20,0x7c,0xbc,0x02,0xbc,0x08,0x47,
	0x00,0x00,0xfe,0x09,0x00,0x00,0x00,0x08,
	0x00,0x00,0x02,0x08,0x00,0x00,0x04,0x08,
	0x00,0x00,0xc0,0x09,0x00,0x00,0xfc,0x09,
};
static unsigned char f1M_102_repl1[]=
{
	0x00,0xb5,0x00,0xF0,
	0x5b,0xFB,0x02,0xbc,0x08,0x47,0x05,0x4A,
};
static unsigned char f1M_102_repl2[]=
{
	0xaa,0x20,0x10,0x78,0x05,0x49,0x55,0x20,
	0x08,0x78,0x90,0x20,0x10,0x78,0x10,0xa9,
};
static unsigned char f1M_102_repl3[]=
{
	0x00,0x05,0x1b,0x24,0x24,0x01,0x24,0x01,
	0x32,0x20,0x04,0x43,0x07,0x49,0xaa,0x20,
	0x08,0x78,0x07,0x4a,0x55,0x20,0x10,0x78,
	0xf0,0x20,0x08,0x78,0x08,0x78,0x10,0xa9,
};
static unsigned char flash1M103_new_identify[]=
{
	0x13,0x23,0x1b,0x02,0x62,0x20,0x03,0x43
};
static unsigned char flash1M103_Setrampage[]=
{
	0x00,0x06,0x00,0x0E,
	0x05,0x4B,0xAA,0x21,0x19,0x70,0x05,0x4A,
};
static unsigned char flash1M103_Erase[]=
{
	0xf0,0xb5,0x90,0xb0,0x00,0x04,0x06,0x0c,
	0x03,0x48,0x00,0x68,0x40,0x89,0x86,0x42,
	0x06,0xd3,0x02,0x48,0x52,0xe0,0x00,0x00,
	0xEC,0x79,0x00,0x03,0xff,0x80,0x00,0x00,
	0x30,0x09,0x00,0x06,0x00,0x0e,0xff,0xf7,
	0x97,0xfc,0x0f,0x20,0x06,0x40,0x00,0x27,
	0x18,0x4b,0x19,0x88,0x18,0x48,0x01,0x40,
	0x18,0x48,0x02,0x68,0x01,0x8a,0x01,0x43,
	0x19,0x80,0x14,0x7a,0x30,0x1c,0xa0,0x40,
	0x04,0x1c,0xe0,0x20,
};
static unsigned char flash1M103_Program[]=
{
	0x10,0xb5,0x0a,0x4c,0xaa,0x22,0x22,0x70,
	0x09,0x4b,0x55,0x22,0x1a,0x70,0xa0,0x22,
	0x22,0x70,0x02,0x78,0x0a,0x70,0x07,0x4B,
	0x02,0x78,0x1b,0x68,0x01,0x20,0x00,0xf0,
	0x63,0xf8,0x00,0x04,0x00,0x0c,0x10,0xbc,
	0x02,0xbc,0x08,0x47,
};
static unsigned char flash1M103_Write[]=//Write
{
	0xf0,0xb5,0x90,0xb0,0x0f,0x1c,0x00,0x04,
	0x04,0x0c,0x03,0x48,0x00,0x68,0x40,0x89,
	0x84,0x42,0x05,0xd3,0x01,0x48,0x40,0xe0,
	0xEc,0x79,0x00,0x03,0xff,0x80,0x00,0x00,
	0x20,0x1c,0xff,0xf7,0x1f,0xff,0x00,0x04,
	0x05,0x0c,0x00,0x2d,0x34,0xd1,0x20,0x09,
	0x00,0x06,0x00,0x0e,0xff,0xf7,0xbc,0xfb,
	0x0f,0x20,0x04,0x40,0x68,0x46,0xff,0xf7,
	0xc1,0xfc,0x09,0x4b,0x19,0x88,0x09,0x48,
	0x01,0x40,0x09,0x48,0x02,0x68,0x10,0x8a,
	0x01,0x43,0x19,0x80,0x07,0x49,0x50,0x68,
	0x08,0x80,0x10,0x7a,0x84,0x40,0xe0,0x20,
	0x00,0x05,0x24,0x18,0x0e,0x1c,0x0c,0xe0,
};
static unsigned char flash1M103_new_Erase[]=
{
	0x00,0xb5,0x00,0x20,0x02,0xbc,0x08,0x47,
	0x70,0xb4,0x0a,0x49,0xd2,0x22,0x12,0x02,
	0x0a,0x80,0x09,0x49,0x15,0x23,0x1b,0x02,
	0x0b,0x80,0x08,0x49,0x0a,0x80,0x08,0x49,
	0x0b,0x80,0x08,0x49,0x00,0x01,0x00,0x30,
	0x08,0x80,0x07,0x49,0x0b,0x80,0x70,0xbc,
	0x70,0x47,0x00,0x00,0x00,0x00,0xfe,0x09,
	0x00,0x00,0x00,0x08,0x00,0x00,0x02,0x08,
	0x00,0x00,0x04,0x08,0x00,0x00,0xc0,0x09,
	0x00,0x00,0xfc,0x09,
};
static unsigned char flash1M103_new_Write[]=
{
	0x7c,0xb5,0x00,0x06,0x04,0x0f,0x00,0x01,
	0x00,0x0c,0x0a,0x1c,0xe0,0x21,0x09,0x05,
	0x09,0x18,0x01,0x23,0x1b,0x03,0x0e,0x48,
	0xd2,0x25,0x2d,0x02,0x05,0x80,0x0d,0x48,
	0x15,0x26,0x36,0x02,0x06,0x80,0x0c,0x48,
	0x05,0x80,0x0c,0x48,0x06,0x80,0x0c,0x48,
	0x24,0x01,0x00,0x34,0x04,0x80,0x0b,0x48,
	0x06,0x80,0x10,0x78,0x08,0x70,0x01,0x3b,
	0x01,0x32,0x01,0x31,0x00,0x2b,0xf8,0xd1,
	0x00,0x20,0x7c,0xbc,0x02,0xbc,0x08,0x47,
	0x00,0x00,0xfe,0x09,0x00,0x00,0x00,0x08,
	0x00,0x00,0x02,0x08,0x00,0x00,0x04,0x08,
	0x00,0x00,0xc0,0x09,0x00,0x00,0xfc,0x09,
};
static unsigned char flash1M103_new_Setrampage[]=
{
	0x00,0xb5,0x00,0xF0,
	0x55,0xFB,0x02,0xbc,0x08,0x47,0x05,0x4A,
};
static unsigned char flash1M103_new_Program[]=
{
	0x10,0xb5,0x0a,0x4c,0xaa,0x22,0x00,0x00,
	0x09,0x4b,0x55,0x22,0x00,0x00,0xa0,0x22,
	0x00,0x00,0x02,0x78,0x0a,0x70,0x07,0x4B,
	0x02,0x78,0x1b,0x68,0x01,0x20,0x00,0xf0,
	0x63,0xf8,0x00,0x04,0x00,0x0c,0x10,0xbc,
	0x02,0xbc,0x08,0x47,
};

typedef struct _GBAPatchDataHead{
	SAVERTYPE	SaverType;	//	UNKNOW =0,	SRAM_TYPE=1,EEPROM_TYPE=2,FLASH_TYPE=3,FLASH512_TYPE=4,FLASH1M_TYPE=5,
	s32 		dwSaveSize;	//  save size
	s32 		dwPatchNum;	//  patch 
}GBAPatchDataHead;

typedef struct _GBAPatchData{
  char sign[4];
  s32  patchOff;
  s32  patchdatasize;
  u8*  pData;
  _GBAPatchData *pNext;
}GBAPatchData;

extern GBAPatchDataHead g_GBAPatchDataHead;
extern GBAPatchData     *m_pGBAPatchData;



void ModifyFlash(s32 off,u8 *szbuf,s32 len);
u8*	FindMotif(u8 *Buffer, s32 BufferSize, u8 *Motif, s32 MotifSize,s32 *off);
u8* FindSaveType(u8*Buffer,s32 BufferSize,SAVERTYPE *ptype);
s32 GetSaveTypeAndSize(u8 **buf,s32 *length,SAVERTYPE *type,s32 *off);
extern s32 SaverPatch(u8 **buf,s32 *length,s32 saverOffset,SAVERTYPE *dwSaverType,s32 *dwSaveSize);

/*****************PsRam************************/

u8*	FindMotifPsRam(u8 *Buffer, s32 BufferSize, u8 *Motif, s32 MotifSize,s32 *off);
u8* FindSaveTypePsRam(u8* Buffer,s32 BufferSize,SAVERTYPE *ptype);
void WritePSramBK(u8* address, u8* data , uint32 length );
extern s32 SaverPatchPsRam(u8 **buf,s32 *length,s32 saverOffset,SAVERTYPE *dwSaverType,s32 *dwSaveSize);


/*****************PsRam End************************/

extern void FreeQuickPatchData(void);


#endif /*PROC_GBA_PATCH_H_*/
